|
|
|
|
|
|
|
Just as Visual Basic projects use several types of files (module, form, class, etc.), projects written in C or C++ use different types of files as well. The most important file type when it comes to understanding a DLL is the header file, which typically has the extension .h. A header file usually contains the same information as a standard module except that it rarely contains large blocks of code. Instead, it will contain a declaration for each function that is contained in the actual source file (which will have a .C or .CPP extension, depending on whether the program is written in C or C++). |
|
|
|
|
|
|
|
|
Now, this is a simplification; C++ header files can contain a great deal of additional information, but you will rarely need it to access the DLL from Visual Basic. Complex DLLs may use dozens of separate header files and source files. But the only header files you need are the ones that include structure definitions and function declarations that are used by outside applications. You can ignore those header files that are only used within the DLL. Once you find these key header files, all you need to do is convert them to Visual Basic, and you'll be able to access the DLL functions. And teaching you to perform these conversions correctly is one of the major goals of this book. |
|
|
|
|
|
|
|
|
Why worry about learning how to handle C/C++ header files? Why not just rely on the DLL's documentation? |
|
|
|
|
|
|
|
|
There are two main answers to this question. |
|
|
|
|
|
|
|
|
First, many DLLs don't bother including actual structure definitions and function declarations in their documentation. Why? Because DLLs are traditionally intended to be called from other C/C++ programs anyway. It is far easier to just tell a programmer to include a header file that comes with the DLL in their own project.1 |
|
|
|
|
|
|
|
|
That way, the programmer can call the DLL functions directly in their own applications with no further effort on their part. This is one advantage that C/C++ programmers have over VB programmerseverybody provides C/C++ headers for their DLLs. Not everyone includes a Visual Basic module with the correct declarations and structure definitions. |
|
|
|
|
|
|
|
|
The second answer applies to the Win32 API as well. Because the header files are primarily intended to be used by applications rather than read by programmers, they are almost always correct. If they weren't correct, the programs that used them wouldn't work. Incorrect documentation may cause nervous breakdowns among programmers, but it has little other effect. |
|
|
|
|
|
|
|
|
Intel's cpuinf32.dll library includes two header files, speed.h and cpuid.h. The first step in converting these files is to copy them into Visual Basic modules. |
|
|
|
 |
|
 |
|
|
1 C programs can "include" header files using a command called #include. This command causes a header file to be inserted into a program during compilation. There is, unfortunately, no Visual Basic equivalent to this operation at this time. |
|
|
|
|
|